package com.seal.tsms.base.util;

import javax.mail.*;
import java.util.Properties;

public class MailTest {

    public static void main(String[] args) throws Exception{
        Properties props = System.getProperties();

        //props.setProperty("mail.imap.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
        //props.setProperty("mail.imap.socketFactory.fallback", "false");
       // props.put("mail.imap.host", "imap.qq.com");


        //props.put("mail.imap.auth.plain.disable","true");
        props.put("mail.imap.ssl.enable", "true");
        Session session = Session.getDefaultInstance(props, null);
        URLName urln = new URLName("imap", "imap.qq.com", 993, "INBOX",
                "744327309@qq.com", "nixnfvewusbkbfhj");
        Store store = session.getStore(urln);
        store.connect();
        Folder folder = store.getFolder("INBOX");
        folder.open(Folder.READ_ONLY);
        Message[] messages = folder.getMessages();
        System.out.println("邮件个数: " + folder.getMessageCount());
        System.out.println("未读邮件个数:" + folder.getUnreadMessageCount());
        System.out.println("新邮件个数:" + folder.getUnreadMessageCount());

        for (Message message : messages){
            //遍历邮件
            System.out.println(message.getSubject());

        }
    }

    /*

    public static void main(String[] args) throws Exception{
        Properties props = System.getProperties();
        props.setProperty("mail.imap.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
//  props.setProperty("mail.imap.socketFactory.fallback", "false");
//     props.setProperty("mail.imap.port", port);
        props.setProperty("mail.imap.socketFactory.port", "993");


        props.setProperty("mail.store.protocol","imap");
        props.setProperty("mail.imap.host",  "imap.qq.com");
        props.setProperty("mail.imap.port", "993");
        props.setProperty("mail.imap.auth.login.disable", "true");

        Session session = Session.getDefaultInstance(props, null);

        session.setDebug(false);
        Store store = session.getStore("imap");
        store.connect("imap.qq.com","744327309@qq.com","nixnfvewusbkbfhj");
        Folder folder = store.getFolder("INBOX");
        folder.open(Folder.READ_ONLY);
        Message[] messages = folder.getMessages();
        System.out.println("邮件个数: " + folder.getMessageCount());
        System.out.println("未读邮件个数:" + folder.getUnreadMessageCount());
        System.out.println("新邮件个数:" + folder.getUnreadMessageCount());

        for (Message message : messages){
            //遍历邮件
            System.out.println(message.getSubject());

        }
    }


     */
}
